/* eslint-disable no-unused-vars */

import moduleCreator from '../moduleCreator'

import api from '@/api'

const modelName = 'consult.consultation'

const state = {
  //
}

const mutations = {
  //
}

const actions = {
  async search({ commit, state, dispatch }, payload) {
    return dispatch('_search', payload)
  },
  async browse_one({ commit, state, dispatch }, payload) {
    return dispatch('_browse_one', payload)
  },

  async message_post({ commit, state, dispatch }, payload) {
    // console.log('message_post', payload)
    const { id } = payload
    const Model = api.env(modelName)

    const channel = this.state.appChat.channel
    // const user_partner_id = this.state.user.partner_id

    const payload2 = {
      body: '',
      // author_id: user_partner_id,
      author_id: channel.me_partner_id,
      channel_ids: [channel.id]
    }

    const res2 = Model.call('message_post', [id], payload2)

    return new Promise(resolve => {
      resolve()
    })
  }
}

export default moduleCreator(modelName, {
  namespaced: true,
  state,
  mutations,
  actions
})
